/*
 * Created: Author: Aléx Carvalho / Date: Jan 23, 2015
 * 
 * Changed: $Author: ac280593@gmail.com $ / $Date: 2015-06-11 01:28:43 -0300 (Thu, 11 Jun 2015) $
 */
package com.cpm.entities;

import com.cpm.entities.types.Family;
import com.cpm.entities.id.CompetenceId;
import com.cpm.wrapper.Performance;
import com.cpm.wrapper.Result;
import com.cpm.wrapper.Target;
import com.cpm.wrapper.Tendency;
import java.sql.Date;
import java.time.LocalDate;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.ManyToOne;

@Entity
@IdClass(CompetenceId.class)
public class Competence implements Identity<Competence> {

    @Id
    @ManyToOne(optional = false)
    private Indicator indicator;

    // quando se usa a notação id os converters não funcionam
    @Id
    private Date competencePeriod; 

    private Target target;

    private Result result;

    private Tendency tendency;

    private Performance performance;

    public Competence() {
    }

    public Competence(Indicator indicator, LocalDate competencePeriod, Target target, Result result, Tendency tendency, Performance performance) {
        this.indicator = indicator;
        this.competencePeriod = Date.valueOf(competencePeriod);
        this.target = target;
        this.result = result;
        this.tendency = tendency;
        this.performance = performance;
    }

    public Indicator getIndicator() {
        return indicator;
    }

    public LocalDate getPeriod() {
        return competencePeriod.toLocalDate();
    }

    public Target getTarget() {
        return target;
    }

    public void setTarget(Target target) {
        this.target = target;
    }

    public Result getResult() {
        return result;
    }

    public void setResult(Result result) {
        this.result = result;
    }

    public Tendency getTendency() {
        return tendency;
    }

    public void setTendency(Tendency tendency) {
        this.tendency = tendency;
    }

    public Performance getPerformance() {
        return performance;
    }

    public void setPerformance(Performance performance) {
        this.performance = performance;
    }

    @Override
    public Family getFamily() {
        return Family.COMPETENCE;
    }

    @Override
    public Competence clone() {
        return null;
    }
    
    @Override
    public int hashCode() {
        int hash = 3;
        hash = 97 * hash + Objects.hashCode(this.indicator);
        hash = 97 * hash + Objects.hashCode(this.competencePeriod);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }

        if (obj instanceof Competence) {
            Competence other = (Competence) obj;

            return indicator.equals(other.indicator) && competencePeriod.equals(other.competencePeriod);
        }

        return false;
    }

    @Override
    public String toString() {
        return indicator + " - " + competencePeriod; 
    }
    
    public static CompetenceBuilder builder() {
        return new CompetenceBuilder();
    }
}
